package com.loong.seller.handler;

import com.loong.common.domain.BaseQuery;
import com.loong.common.domain.Pager;
import com.loong.common.executor.BatchExecutor;
import com.loong.common.utils.TransformUtils;
import com.loong.seller.business.ShopTypeBusiness;
import com.loong.seller.common.backend.param.ShopTypeParam;
import com.loong.seller.common.backend.param.ShopTypeQueryParam;
import com.loong.seller.common.backend.result.ShopTypeResult;
import com.loong.seller.common.forehead.param.ShopTypeQueryForeheadParam;
import com.loong.seller.common.forehead.result.ShopTypeForeheadResult;
import com.loong.seller.model.ShopType;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 店铺类型服务
 * @Author: hzp
 * @Date: 2020-12-3 9:25
 */
@Service
public class ShopTypeHandler {
    @Resource
    private ShopTypeBusiness shopTypeBusiness;

    @Resource
    private BatchExecutor batchExecutor;

    public void save(ShopTypeParam param) {
        shopTypeBusiness.save(TransformUtils.transform(param, ShopType.class));
    }

    public void update(ShopTypeParam param) {
        shopTypeBusiness.updateByPrimaryKeySelective(TransformUtils.transform(param, ShopType.class));
    }

    public void deleteById(Long id) {
        shopTypeBusiness.deleteById(id);
    }

    public void batchDelete(List<Long> ids){
        batchExecutor.batchExecute(ids,id->id.toString(),id->{shopTypeBusiness.deleteById(id);});
    }

    public ShopTypeResult findShopTypeById(Long id) {
        return TransformUtils.transform(shopTypeBusiness.findById(id), ShopTypeResult.class);
    }

    /**
     * 分页查询 后台使用
     * @param baseQuery 后台分页对象
     * @param param 后台查询参数
     * @return 返回后台需要结果集
     */
    public Pager<ShopTypeResult> pageQuery(BaseQuery baseQuery, ShopTypeQueryParam param){
        Pager<ShopType> manageApisPager = shopTypeBusiness.pageQuery(baseQuery, () -> shopTypeBusiness.query(param));
        return TransformUtils.transformPage(manageApisPager, ShopTypeResult.class);
    }

    /**
     * 分页查询 c端使用
     * @param param 后台查询参数
     * @return 返回前台需要结果集
     */
    public Pager<ShopTypeForeheadResult> pageQuery(ShopTypeQueryForeheadParam param){
        Pager<ShopType> manageApisPager = shopTypeBusiness.pageQuery(param, () -> shopTypeBusiness.query(TransformUtils.transform(param,ShopTypeQueryParam.class)));
        return TransformUtils.transformPage(manageApisPager, ShopTypeForeheadResult.class);
    }

    /**
     * 查询所有 c端使用
     */
    public List<ShopTypeForeheadResult> findAll() {
        return TransformUtils.transformList(shopTypeBusiness.findAll(),ShopTypeForeheadResult.class);
    }

    public List<ShopTypeForeheadResult> findShopTypeByType( Integer type){
        return TransformUtils.transformList(shopTypeBusiness.findAllBy("type",type),ShopTypeForeheadResult.class);

    }
}
